import bisect
class Solution(object):
    def waysToSplit(self, nums):
        base = 10 ** 9 + 7
        n = len(nums)
        for i in range(1, n):
            nums[i] += nums[i - 1]
        ans = 0
        for i in range(n - 2):
            if nums[i] <= nums[-1] // 3:
                right_mid = (nums[-1] - nums[i]) // 2 + nums[i]
                right_index = bisect.bisect_right(nums, right_mid)
                left_mid = 2 * nums[i]
                left_index = bisect.bisect_left(nums, left_mid)
                if left_index <= i:
                    left_index = i + 1
                if right_index == n:
                    right_index -= 1
                ans += max(right_index - left_index, 0)
            else:
                break
        return ans % base

data = Solution()
nums = [1, 1, 1]
print(data.waysToSplit(nums))